 package handling.channel.handler;


import client.MapleCharacter;
import client.MapleClient;
import client.inventory.Item;
import client.inventory.ItemFlag;
import client.inventory.MapleInventoryType;
import configs.ServerConfig;
import constants.ItemConstants;
import constants.ServerConstants;
import handling.opcode.InteractionOpcode;
import handling.world.WorldBroadcastService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import server.MapleInventoryManipulator;
import server.MapleItemInformationProvider;
import server.MapleTrade;
import server.maps.FieldLimitType;
import server.maps.MapleMapObject;
import server.maps.MapleMapObjectType;
import server.shops.*;
import tools.DateUtil;
import tools.MaplePacketCreator;
import tools.Pair;
import tools.StringUtil;
import tools.data.input.LittleEndianAccessor;
import tools.packet.PlayerShopPacket;

import java.util.Arrays;

 public class PlayerInteractionHandler {
/*  33 */   private static final Logger log = LogManager.getLogger(PlayerInteractionHandler.class); public static void PlayerInteraction(LittleEndianAccessor slea, MapleClient c, MapleCharacter chr) { byte createType; MapleCharacter chrr; String message; IMaplePlayerShop iMaplePlayerShop2; MapleInventoryType ivType; MapleTrade trade; MapleInventoryType mapleInventoryType1; int item; byte type; int slot; IMaplePlayerShop iMaplePlayerShop1, imps, merchant, shop, ips; Item item1; short s1, quantity; int obid; IMaplePlayerShop iMaplePlayerShop3; short s2, bundles; IMaplePlayerShop iMaplePlayerShop4; MaplePlayerShopItem maplePlayerShopItem1; byte targetSlot; short perBundle; MaplePlayerShopItem tobuy; long price, check; IMaplePlayerShop iMaplePlayerShop5; long check2; Item ivItem;
     MapleItemInformationProvider ii;
     long check3;
/*  36 */     byte mode = slea.readByte();
/*  37 */     InteractionOpcode action = InteractionOpcode.getByAction(mode);
/*  38 */     if (chr == null || action == null || c.getChannelServer().isShutdown()) {
/*  39 */       if (ServerConstants.isShowPacket()) {
/*  40 */         System.out.println("玩家互动未知的操作类型: 0x" + StringUtil.getLeftPaddedStr(Integer.toHexString(mode).toUpperCase(), '0', 2) + " " + slea.toString());
       }
/*  42 */       c.sendEnableActions();
       return;
     }
/*  45 */     if (chr.getAntiMacro().inProgress()) {
/*  46 */       chr.dropMessage(5, "被使用测谎仪时无法操作。");
/*  47 */       c.sendEnableActions();
       return;
     }
/*  50 */     chr.setScrolledPosition((short)0);
/*  51 */     if (chr.isAdmin()) {
/*  52 */       chr.dropMessage(5, "玩家互动操作类型: " + action);
     }
/*  54 */     switch (action) {
       case 创建:
/*  56 */         createType = slea.readByte();
/*  57 */         if (createType == 4) {
/*  58 */           if (ServerConfig.WORLD_BANTRADE) {
/*  59 */             chr.dropMessage(1, "管理员禁用了交易功能.");
/*  60 */             c.sendEnableActions();
             return;
           }
/*  63 */           MapleTrade.startTrade(chr);
/*  64 */         } else if (createType == 1 || createType == 2 || createType == 5 || createType == 6 || createType == 75) {
/*  65 */           if (!chr.getMap().getMapObjectsInRange(chr.getTruePosition(), 20000.0D, Arrays.asList(new MapleMapObjectType[] { MapleMapObjectType.SHOP, MapleMapObjectType.HIRED_MERCHANT })).isEmpty() || !chr.getMap().getPortalsInRange(chr.getTruePosition(), 20000.0D).isEmpty()) {
/*  66 */             chr.dropMessage(1, "无法在这个地方使用.");
/*  67 */             c.sendEnableActions(); return;
           }
/*  69 */           if ((createType == 1 || createType == 2) && (
/*  70 */             FieldLimitType.Minigames.check(chr.getMap().getFieldLimit()) || chr.getMap().allowPersonalShop())) {
/*  71 */             chr.dropMessage(1, "无法在这个地方使用.");
/*  72 */             c.sendEnableActions();

             return;
           }
/*  76 */           String desc = slea.readMapleAsciiString();
/*  77 */           String pass = "";
/*  78 */           if (slea.readByte() > 0) {
/*  79 */             pass = slea.readMapleAsciiString();
           }
/*  81 */           if (createType == 1 || createType == 2) {
/*  82 */             slea.readShort();
/*  83 */             int piece = slea.readByte();
/*  84 */             int itemId = (createType == 1) ? (4080000 + piece) : 4080100;
/*  85 */             MapleMiniGame game = new MapleMiniGame(chr, itemId, desc, pass, createType);
/*  86 */             game.setPieceType(piece);
/*  87 */             chr.setPlayerShop((IMaplePlayerShop)game);
/*  88 */             game.setAvailable(true);
/*  89 */             game.setOpen(true);
/*  90 */             game.send(c);
/*  91 */             chr.getMap().addMapObject((MapleMapObject)game);
/*  92 */             game.update();
/*  93 */           } else if (chr.getMap().allowPersonalShop() || (createType == 75 && chr.getMap().allowFishing())) {
/*  94 */             Item item2 = c.getPlayer().getInventory(MapleInventoryType.CASH).getItem(slea.readShort());
/*  95 */             if (item2 == null || item2.getQuantity() <= 0 || item2.getItemId() != slea.readInt()) {
               return;
             }
/*  98 */             if (createType == 5) {
/*  99 */               MaplePlayerShop mps = new MaplePlayerShop(chr, item2.getItemId(), desc);
/* 100 */               chr.setPlayerShop((IMaplePlayerShop)mps);
/* 101 */               chr.getMap().addMapObject((MapleMapObject)mps);
/* 102 */               c.announce(PlayerShopPacket.getPlayerStore(chr, true));
/* 103 */             } else if (HiredMerchantHandler.UseHiredMerchant(chr.getClient(), false)) {

/* 105 */               HiredMerchant merch = new HiredMerchant(chr, item2.getItemId(), desc);
/* 106 */               chr.setPlayerShop((IMaplePlayerShop)merch);
/* 107 */               chr.getMap().addMapObject((MapleMapObject)merch);
/* 108 */               c.announce(PlayerShopPacket.getHiredMerch(chr, merch, true));
/* 109 */             } else if (createType == 75 && HiredFisherHandler.INSTANCE.check(c, false)) {
/* 110 */               c.announce(PlayerShopPacket.FishNotice());
/* 111 */               int time = (item2.getItemId() >= 5601000 && item2.getItemId() <= 5601002) ? ((item2.getItemId() - 5601000 + 1) * 6) : 0;
/* 112 */               HiredFisher fisher = new HiredFisher(chr, item2.getItemId(), time);
/* 113 */               fisher.setId(c.getChannelServer().addFisher(fisher));
/* 114 */               chr.setHiredFisher(fisher);
/* 115 */               if (fisher.isHiredFisherItemId()) {
/* 116 */                 chr.removeItem(item2.getItemId(), 1);
               }
/* 118 */               chr.getMap().addMapObject((MapleMapObject)fisher);
/* 119 */               c.announce(PlayerShopPacket.spawnHiredMerchant((AbstractPlayerStore)fisher));
/* 120 */               c.announce(PlayerShopPacket.FishExit());
/* 121 */               c.announce(PlayerShopPacket.updateHiredMerchant((AbstractPlayerStore)fisher));
             }
           }
         }
         return;


       case 交易邀请:
/* 129 */         if (chr.getMap() == null) {
           return;
         }
/* 132 */         chrr = chr.getMap().getCharacterById(slea.readInt());
/* 133 */         if (chrr == null || c.getChannelServer().isShutdown() || chrr.hasBlockedInventory()) {
/* 134 */           c.sendEnableActions();
           return;
         }
/* 137 */         MapleTrade.inviteTrade(chr, chrr);
         return;

       case 拒绝邀请:
/* 141 */         MapleTrade.declineTrade(chr);
         return;

       case 访问:
/* 145 */         if (c.getChannelServer().isShutdown()) {
/* 146 */           c.sendEnableActions();
           return;
         }
/* 149 */         if (chr.getTrade() != null && chr.getTrade().getPartner() != null && !chr.getTrade().inTrade()) {
/* 150 */           MapleTrade.visitTrade(chr, chr.getTrade().getPartner().getChr());
/* 151 */         } else if (chr.getMap() != null && chr.getTrade() == null) {
/* 152 */           int i = slea.readInt();
/* 153 */           MapleMapObject ob = chr.getMap().getMapObject(i, MapleMapObjectType.HIRED_MERCHANT);
/* 154 */           if (ob == null) {
/* 155 */             ob = chr.getMap().getMapObject(i, MapleMapObjectType.SHOP);
           }
/* 157 */           if (ob instanceof IMaplePlayerShop && chr.getPlayerShop() == null) {
/* 158 */             IMaplePlayerShop iMaplePlayerShop = (IMaplePlayerShop)ob;
/* 159 */             if (ob instanceof HiredMerchant) {
/* 160 */               HiredMerchant hiredMerchant = (HiredMerchant)iMaplePlayerShop;
/* 161 */               if (hiredMerchant.isOwner(chr) && hiredMerchant.isOpen() && hiredMerchant.isAvailable()) {
/* 162 */                 hiredMerchant.setOpen(false);
/* 163 */                 hiredMerchant.removeAllVisitors(20, 1);
/* 164 */                 chr.setPlayerShop(iMaplePlayerShop);
/* 165 */                 c.announce(PlayerShopPacket.getHiredMerch(chr, hiredMerchant, false));
               }
/* 167 */               else if (!hiredMerchant.isOpen() || !hiredMerchant.isAvailable()) {
/* 168 */                 chr.dropMessage(1, "主人正在整理商店物品\r\n请稍后再度光临！");
               }
/* 170 */               else if (iMaplePlayerShop.getFreeSlot() == -1) {
/* 171 */                 chr.dropMessage(1, "店铺已达到最大人数\r\n请稍后再度光临！");
/* 172 */               } else if (hiredMerchant.isInBlackList(chr.getName())) {
/* 173 */                 chr.dropMessage(1, "你被禁止进入该店铺");
               } else {
/* 175 */                 chr.setPlayerShop(iMaplePlayerShop);
/* 176 */                 hiredMerchant.addVisitor(chr);
/* 177 */                 c.announce(PlayerShopPacket.getHiredMerch(chr, hiredMerchant, false));

               }

             }
/* 182 */             else if (iMaplePlayerShop instanceof MaplePlayerShop && ((MaplePlayerShop)iMaplePlayerShop).isBanned(chr.getName())) {
/* 183 */               c.announce(PlayerShopPacket.shopErrorMessage(true, 17, 0));
             }
/* 185 */             else if (iMaplePlayerShop.getFreeSlot() < 0 || iMaplePlayerShop.getVisitorSlot(chr) > -1 || !iMaplePlayerShop.isOpen() || !iMaplePlayerShop.isAvailable()) {
/* 186 */               c.announce(PlayerShopPacket.getMiniGameFull());
             } else {
/* 188 */               if (slea.available() > 0L && slea.readByte() > 0) {
/* 189 */                 String pass = slea.readMapleAsciiString();
/* 190 */                 if (!pass.equals(iMaplePlayerShop.getPassword())) {
/* 191 */                   c.getPlayer().dropMessage(1, "你输入的密码不正确.");
                   return;
                 }
/* 194 */               } else if (iMaplePlayerShop.getPassword().length() > 0) {
/* 195 */                 c.getPlayer().dropMessage(1, "你输入的密码不正确.");
                 return;
               }
/* 198 */               chr.setPlayerShop(iMaplePlayerShop);
/* 199 */               iMaplePlayerShop.addVisitor(chr);
/* 200 */               if (iMaplePlayerShop instanceof MapleMiniGame) {
/* 201 */                 ((MapleMiniGame)iMaplePlayerShop).send(c);
               } else {
/* 203 */                 c.announce(PlayerShopPacket.getPlayerStore(chr, false));
               }
             }
           }
         }
         return;



       case 聊天:
/* 213 */         chr.updateTick(slea.readInt());
/* 214 */         message = slea.readMapleAsciiString();
/* 215 */         if (chr.getTrade() != null) {
/* 216 */           chr.getTrade().chat(message);
/* 217 */         } else if (chr.getPlayerShop() != null) {
/* 218 */           IMaplePlayerShop iMaplePlayerShop = chr.getPlayerShop();
/* 219 */           iMaplePlayerShop.broadcastToVisitors(PlayerShopPacket.playerInterChat(chr.getName() + " : " + message, iMaplePlayerShop.getVisitorSlot(chr), chr.getName()));
/* 220 */           if (iMaplePlayerShop.getShopType() == 1) {
/* 221 */             iMaplePlayerShop.getMessages().add(new Pair(chr.getName() + " : " + message, Byte.valueOf(iMaplePlayerShop.getVisitorSlot(chr))));
           }
/* 223 */           if (chr.getClient().isMonitored()) {
/* 224 */             WorldBroadcastService.getInstance().broadcastGMMessage(MaplePacketCreator.serverNotice(6, chr.getName() + " said in " + iMaplePlayerShop.getOwnerName() + " shop : " + message));
           }
         }
         return;

       case 退出:
/* 230 */         if (chr.getTrade() != null) {
/* 231 */           MapleTrade.cancelTrade(chr.getTrade(), chr.getClient(), chr);
         } else {
/* 233 */           IMaplePlayerShop iMaplePlayerShop = chr.getPlayerShop();
/* 234 */           if (iMaplePlayerShop == null) {
             return;
           }
/* 237 */           if (iMaplePlayerShop.isOwner(chr) && iMaplePlayerShop.getShopType() != 1) {
/* 238 */             iMaplePlayerShop.closeShop(false, iMaplePlayerShop.isAvailable());
           } else {
/* 240 */             iMaplePlayerShop.removeVisitor(chr);
           }
/* 242 */           chr.setPlayerShop(null);
         }
         return;


       case 打开:
/* 248 */         iMaplePlayerShop2 = chr.getPlayerShop();
/* 249 */         if (iMaplePlayerShop2 != null && iMaplePlayerShop2.isOwner(chr) && iMaplePlayerShop2.getShopType() < 3 && !iMaplePlayerShop2.isAvailable()) {
/* 250 */           if (chr.getMap().allowPersonalShop()) {
/* 251 */             if (c.getChannelServer().isShutdown()) {
/* 252 */               chr.dropMessage(1, "服务器即将关闭维护，暂时无法进行此操作。.");
/* 253 */               c.sendEnableActions();
/* 254 */               iMaplePlayerShop2.closeShop((iMaplePlayerShop2.getShopType() == 1), false);
               return;
             }
/* 257 */             if (iMaplePlayerShop2.getShopType() == 1 && HiredMerchantHandler.UseHiredMerchant(chr.getClient(), false)) {
/* 258 */               HiredMerchant hiredMerchant = (HiredMerchant)iMaplePlayerShop2;
/* 259 */               hiredMerchant.setStoreid(c.getChannelServer().addMerchant(hiredMerchant));
/* 260 */               hiredMerchant.setOpen(true);
/* 261 */               hiredMerchant.setAvailable(true);
/* 262 */               iMaplePlayerShop2.saveItems();
/* 263 */               chr.getMap().broadcastMessage(PlayerShopPacket.spawnHiredMerchant((AbstractPlayerStore)hiredMerchant));
/* 264 */               chr.setPlayerShop(null);
/* 265 */             } else if (iMaplePlayerShop2.getShopType() == 2) {
/* 266 */               iMaplePlayerShop2.setOpen(true);
/* 267 */               iMaplePlayerShop2.setAvailable(true);
/* 268 */               iMaplePlayerShop2.update();
             }
           } else {
/* 271 */             chr.getClient().disconnect(true, false);
/* 272 */             c.getSession().close();
           }
         }
         return;


       case 设置物品:
       case 设置物品_001:
       case 设置物品_002:
       case 设置物品_003:
/* 282 */         ivType = MapleInventoryType.getByType(slea.readByte());
/* 283 */         item1 = chr.getInventory(ivType).getItem(slea.readShort());
/* 284 */         s2 = slea.readShort();
/* 285 */         targetSlot = slea.readByte();
/* 286 */         if (chr.getTrade() != null && item1 != null) {



/* 290 */           boolean canTrade = true;
/* 291 */           if (item1.getItemId() == 4000463 && !canTrade) {
/* 292 */             chr.dropMessage(1, "该道具无法进行交易.");
/* 293 */             c.sendEnableActions();
/* 294 */           } else if ((s2 <= item1.getQuantity() && s2 >= 0) || ItemConstants.is飞镖道具(item1.getItemId()) || ItemConstants.is子弹道具(item1.getItemId())) {
/* 295 */             chr.getTrade().setItems(c, item1, targetSlot, s2);
           }
         }
         return;

       case 设置金币:
       case 设置金币_005:
       case 设置金币_006:
       case 设置金币_007:
/* 304 */         trade = chr.getTrade();
/* 305 */         if (trade != null) {
/* 306 */           trade.setMeso(slea.readLong());
         }
         return;

       case 确认交易:
       case 确认交易_009:
       case 确认交易_00A:
       case 确认交易_00B:
/* 314 */         if (chr.getTrade() != null) {
/* 315 */           MapleTrade.completeTrade(chr);
         }
         return;











       case 玩家商店_添加道具:
       case 玩家商店_添加道具003E:
       case 玩家商店_添加道具003F:
       case 玩家商店_添加道具0040:
       case 添加物品:
       case 添加物品_0020:
       case 添加物品_0021:
       case 添加物品_0022:
/* 337 */         mapleInventoryType1 = MapleInventoryType.getByType(slea.readByte());
/* 338 */         s1 = slea.readShort();
/* 339 */         bundles = slea.readShort();
/* 340 */         perBundle = slea.readShort();
/* 341 */         price = slea.readLong();
/* 342 */         if (price <= 0L || bundles <= 0 || perBundle <= 0) {
/* 343 */           chr.dropMessage(1, "添加物品出现错误(1)");
/* 344 */           c.sendEnableActions();
           return;
         }
/* 347 */         iMaplePlayerShop5 = chr.getPlayerShop();
/* 348 */         if (iMaplePlayerShop5 == null || !iMaplePlayerShop5.isOwner(chr) || iMaplePlayerShop5 instanceof MapleMiniGame) {
           return;
         }
/* 351 */         ivItem = chr.getInventory(mapleInventoryType1).getItem(s1);
/* 352 */         ii = MapleItemInformationProvider.getInstance();
/* 353 */         if (ivItem != null) {
/* 354 */           long l = (bundles * perBundle);
/* 355 */           if (l > 32767L || l <= 0L) {
             return;
           }
/* 358 */           short bundles_perbundle = (short)(bundles * perBundle);
/* 359 */           if (ivItem.getQuantity() >= bundles_perbundle) {
/* 360 */             short flag = ivItem.getFlag();
/* 361 */             if (ItemFlag.不可交易.check(flag) || ItemFlag.封印.check(flag)) {
/* 362 */               c.sendEnableActions();
               return;
             }
/* 365 */             if ((ii.isDropRestricted(ivItem.getItemId()) || ii.isAccountShared(ivItem.getItemId())) && 
/* 366 */               !ItemFlag.可以交换1次.check(flag) && !ItemFlag.宿命剪刀.check(flag)) {
/* 367 */               c.sendEnableActions();


               return;
             }


/* 374 */             if (ivItem.getItemId() == 4000463) {
/* 375 */               chr.dropMessage(1, "该道具无法进行贩卖.");
/* 376 */               c.sendEnableActions();
               return;
             }
/* 379 */             if (bundles_perbundle >= 50 && ivItem.getItemId() == 2340000) {
/* 380 */               c.setMonitored(true);
             }
/* 382 */             if (ItemConstants.getLowestPrice(ivItem.getItemId()) > price) {
/* 383 */               c.getPlayer().dropMessage(1, "The lowest you can sell this for is " + ItemConstants.getLowestPrice(ivItem.getItemId()));
/* 384 */               c.sendEnableActions();
               return;
             }
/* 387 */             if (ItemConstants.is飞镖道具(ivItem.getItemId()) || ItemConstants.is子弹道具(ivItem.getItemId())) {
/* 388 */               MapleInventoryManipulator.removeFromSlot(c, mapleInventoryType1, s1, ivItem.getQuantity(), true);
/* 389 */               Item sellItem = ivItem.copy();
/* 390 */               iMaplePlayerShop5.addItem(new MaplePlayerShopItem(sellItem, (short)1, price));
             } else {
/* 392 */               MapleInventoryManipulator.removeFromSlot(c, mapleInventoryType1, s1, bundles_perbundle, true);
/* 393 */               Item sellItem = ivItem.copy();
/* 394 */               sellItem.setQuantity(perBundle);
/* 395 */               iMaplePlayerShop5.addItem(new MaplePlayerShopItem(sellItem, bundles, price));
             }
/* 397 */             c.announce(PlayerShopPacket.shopItemUpdate(iMaplePlayerShop5));
           } else {
/* 399 */             chr.dropMessage(1, "添加物品的数量错误。如果是飞镖，子弹之类请充了后在进行贩卖。");
           }
         }
         return;


       case 玩家商店_购买道具:
       case 玩家商店_购买道具0042:
       case 玩家商店_购买道具0043:
       case 玩家商店_购买道具0044:
       case BUY_ITEM_STORE:
       case 雇佣商店_购买道具:
       case 雇佣商店_购买道具0024:
       case 雇佣商店_购买道具0025:
       case 雇佣商店_购买道具0026:
/* 414 */         item = slea.readByte();
/* 415 */         quantity = slea.readShort();

/* 417 */         iMaplePlayerShop4 = chr.getPlayerShop();
/* 418 */         if (iMaplePlayerShop4 == null || iMaplePlayerShop4.isOwner(chr) || iMaplePlayerShop4 instanceof MapleMiniGame || item >= iMaplePlayerShop4.getItems().size()) {
/* 419 */           c.announce(PlayerShopPacket.Merchant_Buy_Error((byte)13));
/* 420 */           c.sendEnableActions();
           return;
         }
/* 423 */         tobuy = iMaplePlayerShop4.getItems().get(item);
/* 424 */         if (tobuy == null) {
/* 425 */           c.announce(PlayerShopPacket.Merchant_Buy_Error((byte)10));
/* 426 */           c.sendEnableActions();
           return;
         }
/* 429 */         check = (tobuy.bundles * quantity);
/* 430 */         check2 = tobuy.price * quantity;
/* 431 */         check3 = (tobuy.item.getQuantity() * quantity);
/* 432 */         if (check <= 0L || check2 > ServerConfig.CHANNEL_PLAYER_MAXMESO || check2 <= 0L || check3 > 32767L || check3 < 0L) {
/* 433 */           c.announce(PlayerShopPacket.Merchant_Buy_Error((byte)13));
/* 434 */           c.sendEnableActions();
           return;
         }
/* 437 */         if (chr.getMeso() - check2 < 0L) {
/* 438 */           c.announce(PlayerShopPacket.Merchant_Buy_Error((byte)2));
/* 439 */           c.sendEnableActions();
           return;
         }
/* 442 */         if (tobuy.bundles < quantity || (tobuy.bundles % quantity != 0 && ItemConstants.isEquip(tobuy.item.getItemId())) || chr
/* 443 */           .getMeso() - check2 > ServerConfig.CHANNEL_PLAYER_MAXMESO || iMaplePlayerShop4.getMeso() + check2 < 0L || iMaplePlayerShop4.getMeso() + check2 > ServerConfig.CHANNEL_PLAYER_MAXMESO) {
/* 444 */           c.announce(PlayerShopPacket.Merchant_Buy_Error((byte)4));
/* 445 */           c.sendEnableActions();
           return;
         }
/* 448 */         if (quantity >= 50 && tobuy.item.getItemId() == 2340000) {
/* 449 */           c.setMonitored(true);
         }
/* 451 */         iMaplePlayerShop4.buy(c, item, quantity);
/* 452 */         iMaplePlayerShop4.broadcastToVisitors(PlayerShopPacket.shopItemUpdate(iMaplePlayerShop4));
         return;








       case 雇佣商店_求购道具:
/* 463 */         chr.dropMessage(1, "当前服务器暂不支持求购道具.");
         return;




       case 雇佣商店_维护:
/* 470 */         slea.skip(1);
/* 471 */         type = slea.readByte();
/* 472 */         slea.skip(3);
/* 473 */         obid = slea.readInt();
/* 474 */         if (type == 6) {
/* 475 */           MapleMapObject ob = chr.getMap().getMapObject(obid, MapleMapObjectType.HIRED_MERCHANT);
/* 476 */           if (ob instanceof IMaplePlayerShop && chr.getPlayerShop() == null) {
/* 477 */             IMaplePlayerShop iMaplePlayerShop = (IMaplePlayerShop)ob;
/* 478 */             if (ob instanceof HiredMerchant) {
/* 479 */               HiredMerchant hiredMerchant = (HiredMerchant)iMaplePlayerShop;
/* 480 */               if (hiredMerchant.isOwner(chr) && hiredMerchant.isOpen() && hiredMerchant.isAvailable()) {
/* 481 */                 hiredMerchant.setOpen(false);
/* 482 */                 hiredMerchant.removeAllVisitors(20, 1);
/* 483 */                 chr.setPlayerShop(iMaplePlayerShop);
/* 484 */                 c.announce(PlayerShopPacket.getHiredMerch(chr, hiredMerchant, false));
               }
/* 486 */               else if (!hiredMerchant.isOpen() || !hiredMerchant.isAvailable()) {
/* 487 */                 chr.dropMessage(1, "主人正在整理商店物品\r\n请稍后再度光临！");
/* 488 */               } else if (iMaplePlayerShop.getFreeSlot() == -1) {
/* 489 */                 chr.dropMessage(1, "店铺已达到最大人数\r\n请稍后再度光临！");
/* 490 */               } else if (hiredMerchant.isInBlackList(chr.getName())) {
/* 491 */                 chr.dropMessage(1, "你被禁止进入该店铺");
               }
             }
           }
         } else {

/* 497 */           c.sendEnableActions();
         }
         return;

       case 移除物品:
/* 502 */         slea.skip(1);
/* 503 */         slot = slea.readShort();
/* 504 */         iMaplePlayerShop3 = chr.getPlayerShop();
/* 505 */         if (chr.isAdmin()) {
/* 506 */           chr.dropMessage(5, "移除商店道具: 道具数量 " + iMaplePlayerShop3.getItems().size() + " slot " + slot);
         }
/* 508 */         if (iMaplePlayerShop3 == null || !iMaplePlayerShop3.isOwner(chr) || iMaplePlayerShop3 instanceof MapleMiniGame || iMaplePlayerShop3.getItems().size() <= 0 || iMaplePlayerShop3.getItems().size() <= slot || slot < 0) {
           return;
         }
/* 511 */         maplePlayerShopItem1 = iMaplePlayerShop3.getItems().get(slot);
/* 512 */         if (maplePlayerShopItem1 != null && 
/* 513 */           maplePlayerShopItem1.bundles > 0) {
/* 514 */           Item item_get = maplePlayerShopItem1.item.copy();
/* 515 */           check = (maplePlayerShopItem1.bundles * maplePlayerShopItem1.item.getQuantity());
/* 516 */           if (check < 0L || check > 32767L) {
/* 517 */             if (chr.isAdmin()) {
/* 518 */               chr.dropMessage(5, "移除商店道具出错: check " + check);
             }
             return;
           }
/* 522 */           item_get.setQuantity((short)(int)check);
/* 523 */           if (item_get.getQuantity() >= 50 && maplePlayerShopItem1.item.getItemId() == 2340000) {
/* 524 */             c.setMonitored(true);
           }
/* 526 */           if (MapleInventoryManipulator.checkSpace(c, item_get.getItemId(), item_get.getQuantity(), item_get.getOwner())) {
/* 527 */             MapleInventoryManipulator.addFromDrop(c, item_get, false);
/* 528 */             maplePlayerShopItem1.bundles = 0;
/* 529 */             iMaplePlayerShop3.removeFromSlot(slot);
           }
         }

/* 533 */         c.announce(PlayerShopPacket.shopItemUpdate(iMaplePlayerShop3));
         return;

       case 雇佣商店_开启:
       case 雇佣商店_维护开启:
/* 538 */         iMaplePlayerShop1 = chr.getPlayerShop();
/* 539 */         if (iMaplePlayerShop1 != null && iMaplePlayerShop1 instanceof HiredMerchant && iMaplePlayerShop1.isOwner(chr) && iMaplePlayerShop1.isAvailable()) {
/* 540 */           iMaplePlayerShop1.setOpen(true);
/* 541 */           iMaplePlayerShop1.saveItems();
/* 542 */           iMaplePlayerShop1.getMessages().clear();
/* 543 */           iMaplePlayerShop1.removeAllVisitors(-1, -1);
/* 544 */           chr.setPlayerShop(null);
         }
/* 546 */         c.sendEnableActions();
         return;

       case 雇佣商店_整理:
/* 550 */         imps = chr.getPlayerShop();
/* 551 */         if (imps != null && imps.isOwner(chr) && !(imps instanceof MapleMiniGame)) {
/* 552 */           for (int i = 0; i < imps.getItems().size(); i++) {
/* 553 */             if (((MaplePlayerShopItem)imps.getItems().get(i)).bundles == 0) {
/* 554 */               imps.getItems().remove(i);
             }
           }
/* 557 */           if (chr.getMeso() + imps.getMeso() > 0L) {
/* 558 */             chr.gainMeso(imps.getMeso(), false);
/* 559 */             HiredMerchant.log.info(chr.getName() + " 雇佣整理获得金币: " + imps.getMeso() + " 时间: " + DateUtil.getCurrentDate());
/* 560 */             imps.setMeso(0L);
           }
/* 562 */           c.announce(PlayerShopPacket.shopItemUpdate(imps));
         }
         return;

       case 雇佣商店_关闭:
/* 567 */         merchant = chr.getPlayerShop();
/* 568 */         if (merchant != null && merchant.getShopType() == 1 && merchant.isOwner(chr)) {
/* 569 */           c.announce(PlayerShopPacket.hiredMerchantOwnerLeave());
/* 570 */           merchant.removeAllVisitors(-1, -1);
/* 571 */           chr.setPlayerShop(null);
/* 572 */           merchant.closeShop(true, true);
         } else {
/* 574 */           chr.dropMessage(1, "关闭商店出现未知错误.");
/* 575 */           c.sendEnableActions();
         }
         return;


       case 管理员修改雇佣商店名称:
/* 581 */         chr.dropMessage(1, "暂不支持管理员修改雇佣商店的名字.");
/* 582 */         c.sendEnableActions();
         return;

       case 雇佣商店_查看访问名单:
/* 586 */         merchant = chr.getPlayerShop();
/* 587 */         if (merchant != null && merchant.getShopType() == 1 && merchant.isOwner(chr)) {
/* 588 */           ((HiredMerchant)merchant).sendVisitor(c);
         }
         return;

       case 雇佣商店_查看黑名单:
/* 593 */         merchant = chr.getPlayerShop();
/* 594 */         if (merchant != null && merchant.getShopType() == 1 && merchant.isOwner(chr)) {
/* 595 */           ((HiredMerchant)merchant).sendBlackList(c);
         }
         return;

       case 雇佣商店_添加黑名单:
/* 600 */         merchant = chr.getPlayerShop();
/* 601 */         if (merchant != null && merchant.getShopType() == 1 && merchant.isOwner(chr)) {
/* 602 */           ((HiredMerchant)merchant).addBlackList(slea.readMapleAsciiString());
         }
         return;

       case 雇佣商店_移除黑名单:
/* 607 */         merchant = chr.getPlayerShop();
/* 608 */         if (merchant != null && merchant.getShopType() == 1 && merchant.isOwner(chr)) {
/* 609 */           ((HiredMerchant)merchant).removeBlackList(slea.readMapleAsciiString());
         }
         return;

       case 雇佣商店_修改商店名称:
/* 614 */         merchant = chr.getPlayerShop();
/* 615 */         if (merchant != null && merchant.getShopType() == 1 && merchant.isOwner(chr)) {
/* 616 */           String desc = slea.readMapleAsciiString();
/* 617 */           if (((HiredMerchant)merchant).canChangeName()) {
/* 618 */             merchant.setDescription(desc);
           } else {
/* 620 */             c.announce(MaplePacketCreator.craftMessage("还不能变更名称，还需要等待" + ((HiredMerchant)merchant).getChangeNameTimeLeft() + "秒。"));
           }
         }
         return;

       case 玩家商店_移除玩家:
/* 626 */         shop = chr.getPlayerShop();
/* 627 */         if (shop != null && shop.getShopType() == 2) {
/* 628 */           slea.skip(1);
/* 629 */           String name = slea.readMapleAsciiString();
/* 630 */           ((MaplePlayerShop)shop).banPlayer(name);
         }
         return;

       case GIVE_UP:
/* 635 */         ips = chr.getPlayerShop();
/* 636 */         if (ips != null && ips instanceof MapleMiniGame) {
/* 637 */           MapleMiniGame game = (MapleMiniGame)ips;
/* 638 */           if (!game.isOpen()) {


/* 641 */             game.broadcastToVisitors(PlayerShopPacket.getMiniGameResult(game, 0, game.getVisitorSlot(chr)));
/* 642 */             game.nextLoser();
/* 643 */             game.setOpen(true);
/* 644 */             game.update();
/* 645 */             game.checkExitAfterGame();
           }
         }
         return;
       case 踢出玩家:
/* 650 */         ips = chr.getPlayerShop();
/* 651 */         if (ips != null && ips instanceof MapleMiniGame && 
/* 652 */           ips.isOpen())
         {

/* 655 */           ips.removeAllVisitors(3, 1);
         }
         return;

       case 准备就绪:
       case 准备开始:
/* 661 */         ips = chr.getPlayerShop();
/* 662 */         if (ips != null && ips instanceof MapleMiniGame) {
/* 663 */           MapleMiniGame game = (MapleMiniGame)ips;
/* 664 */           if (!game.isOwner(chr) && game.isOpen()) {
/* 665 */             game.setReady(game.getVisitorSlot(chr));
/* 666 */             game.broadcastToVisitors(PlayerShopPacket.getMiniGameReady(game.isReady(game.getVisitorSlot(chr))));
           }
         }
         return;

       case 开始游戏:
/* 672 */         ips = chr.getPlayerShop();
/* 673 */         if (ips != null && ips instanceof MapleMiniGame) {
/* 674 */           MapleMiniGame game = (MapleMiniGame)ips;
/* 675 */           if (game.isOwner(chr) && game.isOpen()) {
/* 676 */             for (int i = 1; i < ips.getSize(); i++) {
/* 677 */               if (!game.isReady(i)) {
                 return;
               }
             }
/* 681 */             game.setGameType();
/* 682 */             game.shuffleList();
/* 683 */             if (game.getGameType() == 1) {
/* 684 */               game.broadcastToVisitors(PlayerShopPacket.getMiniGameStart(game.getLoser()));
             } else {
/* 686 */               game.broadcastToVisitors(PlayerShopPacket.getMatchCardStart(game, game.getLoser()));
             }
/* 688 */             game.setOpen(false);
/* 689 */             game.update();
           }
         }
         return;

       case 请求平局:
/* 695 */         ips = chr.getPlayerShop();
/* 696 */         if (ips != null && ips instanceof MapleMiniGame) {
/* 697 */           MapleMiniGame game = (MapleMiniGame)ips;
/* 698 */           if (!game.isOpen()) {


/* 701 */             if (game.isOwner(chr)) {
/* 702 */               game.broadcastToVisitors(PlayerShopPacket.getMiniGameRequestTie(), false);
             } else {
/* 704 */               game.getMCOwner().getClient().announce(PlayerShopPacket.getMiniGameRequestTie());
             }
/* 706 */             game.setRequestedTie(game.getVisitorSlot(chr));
           }
         }
         return;
       case 应答平局:
/* 711 */         ips = chr.getPlayerShop();
/* 712 */         if (ips != null && ips instanceof MapleMiniGame) {
/* 713 */           MapleMiniGame game = (MapleMiniGame)ips;
/* 714 */           if (!game.isOpen())
           {

/* 717 */             if (game.getRequestedTie() > -1 && game.getRequestedTie() != game.getVisitorSlot(chr)) {
/* 718 */               if (slea.readByte() > 0) {
/* 719 */                 game.broadcastToVisitors(PlayerShopPacket.getMiniGameResult(game, 1, game.getRequestedTie()));
/* 720 */                 game.nextLoser();
/* 721 */                 game.setOpen(true);
/* 722 */                 game.update();
/* 723 */                 game.checkExitAfterGame();
               } else {
/* 725 */                 game.broadcastToVisitors(PlayerShopPacket.getMiniGameDenyTie());
               }
/* 727 */               game.setRequestedTie(-1);
             }
           }
         }
         return;
       case SKIP:
/* 733 */         ips = chr.getPlayerShop();
/* 734 */         if (ips != null && ips instanceof MapleMiniGame) {
/* 735 */           MapleMiniGame game = (MapleMiniGame)ips;
/* 736 */           if (!game.isOpen()) {


/* 739 */             if (game.getLoser() != ips.getVisitorSlot(chr)) {
/* 740 */               ips.broadcastToVisitors(PlayerShopPacket.playerInterChat("Turn could not be skipped by " + chr.getName() + ". Loser: " + game.getLoser() + " Visitor: " + ips.getVisitorSlot(chr), ips.getVisitorSlot(chr), chr.getName()));
               return;
             }
/* 743 */             ips.broadcastToVisitors(PlayerShopPacket.getMiniGameSkip(ips.getVisitorSlot(chr)));
/* 744 */             game.nextLoser();
           }
         }
         return;
       case 移动棋子:
/* 749 */         ips = chr.getPlayerShop();
/* 750 */         if (ips != null && ips instanceof MapleMiniGame) {
/* 751 */           MapleMiniGame game = (MapleMiniGame)ips;
/* 752 */           if (!game.isOpen()) {


/* 755 */             if (game.getLoser() != game.getVisitorSlot(chr)) {
/* 756 */               game.broadcastToVisitors(PlayerShopPacket.playerInterChat("Omok could not be placed by " + chr.getName() + ". Loser: " + game.getLoser() + " Visitor: " + game.getVisitorSlot(chr), game.getVisitorSlot(chr), chr.getName()));
               return;
             }
/* 759 */             game.setPiece(slea.readInt(), slea.readInt(), slea.readByte(), chr);
           }
         }
         return;
       case 选择卡片:
/* 764 */         ips = chr.getPlayerShop();
/* 765 */         if (ips != null && ips instanceof MapleMiniGame) {
/* 766 */           MapleMiniGame game = (MapleMiniGame)ips;
/* 767 */           if (!game.isOpen()) {


/* 770 */             if (game.getLoser() != game.getVisitorSlot(chr)) {
/* 771 */               game.broadcastToVisitors(PlayerShopPacket.playerInterChat("Card could not be placed by " + chr.getName() + ". Loser: " + game.getLoser() + " Visitor: " + game.getVisitorSlot(chr), game.getVisitorSlot(chr), chr.getName()));
               return;
             }
/* 774 */             if (slea.readByte() != game.getTurn()) {
/* 775 */               game.broadcastToVisitors(PlayerShopPacket.playerInterChat("Omok could not be placed by " + chr.getName() + ". Loser: " + game.getLoser() + " Visitor: " + game.getVisitorSlot(chr) + " Turn: " + game.getTurn(), game.getVisitorSlot(chr), chr.getName()));
               return;
             }
/* 778 */             int i = slea.readByte();
/* 779 */             int turn = game.getTurn();
/* 780 */             int fs = game.getFirstSlot();
/* 781 */             if (turn == 1) {
/* 782 */               game.setFirstSlot(i);
/* 783 */               if (game.isOwner(chr)) {
/* 784 */                 game.broadcastToVisitors(PlayerShopPacket.getMatchCardSelect(turn, i, fs, turn), false);
               } else {
/* 786 */                 game.getMCOwner().getClient().announce(PlayerShopPacket.getMatchCardSelect(turn, i, fs, turn));
               }
/* 788 */               game.setTurn(0); return;
             }
/* 790 */             if (fs > 0 && game.getCardId(fs + 1) == game.getCardId(i + 1)) {
/* 791 */               game.broadcastToVisitors(PlayerShopPacket.getMatchCardSelect(turn, i, fs, game.isOwner(chr) ? 2 : 3));
/* 792 */               game.setPoints(game.getVisitorSlot(chr));
             } else {
/* 794 */               game.broadcastToVisitors(PlayerShopPacket.getMatchCardSelect(turn, i, fs, game.isOwner(chr) ? 0 : 1));
/* 795 */               game.nextLoser();
             }
/* 797 */             game.setTurn(1);
/* 798 */             game.setFirstSlot(0);
           }
         }
         return;
       case 退出游戏:
       case 取消退出:
/* 804 */         ips = chr.getPlayerShop();
/* 805 */         if (ips != null && ips instanceof MapleMiniGame) {
/* 806 */           MapleMiniGame game = (MapleMiniGame)ips;
/* 807 */           if (!game.isOpen()) {


/* 810 */             game.setExitAfter(chr);
/* 811 */             game.broadcastToVisitors(PlayerShopPacket.getMiniGameExitAfter(game.isExitAfter(chr)));
           }
         }
         return;
     }
/* 816 */     if (ServerConstants.isShowPacket()) {
/* 817 */       log.warn("玩家互动未知的操作类型: 0x" + StringUtil.getLeftPaddedStr(Integer.toHexString(mode).toUpperCase(), '0', 2) + " " + slea.toString());
     }
/* 819 */     c.sendEnableActions(); }

 }


/* Location:              C:\PGX\Server.jar!\handling\channel\handler\PlayerInteractionHandler.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */